package model.action;

import java.util.List;
import model.exception.ActionException;
import datacontainer.ImmuTable;


/**
 * This class will add a new column to the workspace from
 * the rawdata file. The user just needs to specify which
 * column to add, and the object will add it.
 * 
 * @author Michael Deng
 * 
 */
public class AddColumn extends ColumnAction {

    /**
     * @param column name of column to add
     * @param conditions list of conditions
     */
    @Override
    public void setInput (String column, List<String> conditions) {
        super.setInput(column, conditions);
    }

    @Override
    public void execute (ImmuTable workSpace, ImmuTable rawData) {
        String myColumn = super.getColumnName();
        int index = getRawDataColumnIndex(rawData, myColumn);
        if (index != -1) {
            if (getWorkSpaceColumnIndex(workSpace, myColumn) == -1) {
                addColumn(workSpace, rawData, index);
            }
            else {
                throw new ActionException("Column already in workspace!");
            }
        }
        else {
            throw new ActionException("Column not found in imported data!");
        }
    }
}
